package org.gaaidou.ptarmigan.springboot.data.jpa.datasource;

import java.util.function.Supplier;

public class DataSourceRouteHelper {


    public static <T> T route(String key, Supplier<T> fn) {
        try {
            RouteStrategyHolder.use(key);
            return fn.get();
        } finally {
            RouteStrategyHolder.clear();
        }
    }

    public static void route(String key, Runnable fn) {
        try {
            RouteStrategyHolder.use(key);
            fn.run();
        } finally {
            RouteStrategyHolder.clear();
        }
    }
}
